package com.linsir.model;

import com.jfinal.core.Controller;
import com.linsir.common.base.BaseModel;
import com.linsir.common.utils.web.RequestUtil;
import com.linsir.config.EovaConst;

/**
 * @author linsir
 * @title: EovaLog
 * @projectName linsir-mu
 * @description: 系统操作日志
 * @date 2021/12/2 21:53
 */
public class EovaLog extends BaseModel<EovaLog> {

    private static final long serialVersionUID = -1592533967096109392L;

    public static final EovaLog dao = new EovaLog();

    /** 新增 **/
    public static final int ADD = 1;
    /** 修改 **/
    public static final int UPDATE = 2;
    /** 删除 **/
    public static final int DELETE = 3;
    /** 导入 **/
    public static final int IMPORT = 4;

    /**
     * 操作日志
     * @param con
     * @param info 日志详情
     */
    public void info(Controller con, int type, String info){
        EovaLog el = new EovaLog();
        // TYPE
        el.set("type", type);
        // UID
        User user = con.getSessionAttr(EovaConst.USER);
        el.set("user_id", user.get("id"));
        // IP
        String ip = RequestUtil.getIp(con.getRequest());
        el.set("ip", ip);
        el.set("info", info);
        el.save();
    }
}
